package com.luhongzhe;

import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * @author 	luhongzhe
 * @email  	azhe0660@gmail.com
 * @date   	2011-6-26
 */

public class TopPage extends Activity
{
	ListView listView;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.top);
		
		listView = (ListView)findViewById(R.id.topPageListView);
		
		init();
	}
	
	private void init()
	{
		DocumentBuilderFactory docBuilderFactory = null;
		DocumentBuilder docBuilder = null;
		Document doc = null;
		
		try
		{
			docBuilderFactory = DocumentBuilderFactory.newInstance();
			docBuilder = docBuilderFactory.newDocumentBuilder();
			doc = docBuilder.parse(getResources().getAssets().open("top.xml"));
			
			Element root = doc.getDocumentElement();
			NodeList nodeList = root.getElementsByTagName("result");
			
			List<String> data = new ArrayList<String>();
			for (int i = 0; i < nodeList.getLength(); i++)
			{
				Node node = nodeList.item(i);
				String result = ((Element)node).getAttribute("text");
				data.add(result);
			}
			
			ListAdapter adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_expandable_list_item_1, data);
			listView.setAdapter(adapter);
		}
		catch (Exception e) {}
	}
	
}
